import logging
import functools
import time
import json
from typing import Any, Callable
from pathlib import Path
from datetime import datetime

class LogManager:
    _instance = None
    _loggers = {}
    
    def __new__(cls):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
        return cls._instance
    
    def __init__(self):
        self.log_path = Path("logs")
        self.log_path.mkdir(exist_ok=True)
        
    def get_logger(self, name: str) -> logging.Logger:
        """获取指定名称的logger"""
        if name not in self._loggers:
            logger = logging.getLogger(name)
            logger.setLevel(logging.DEBUG)
            
            # 创建文件处理器
            log_file = self.log_path / f"{name}_{datetime.now().strftime('%Y%m%d')}.log"
            file_handler = logging.FileHandler(log_file, encoding='utf-8')
            file_handler.setLevel(logging.DEBUG)
            
            # 创建控制台处理器
            console_handler = logging.StreamHandler()
            console_handler.setLevel(logging.INFO)
            
            # 设置日志格式
            formatter = logging.Formatter(
                '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
            )
            file_handler.setFormatter(formatter)
            console_handler.setFormatter(formatter)
            
            logger.addHandler(file_handler)
            logger.addHandler(console_handler)
            
            self._loggers[name] = logger
            
        return self._loggers[name]

# 创建日志管理器实例
log_manager = LogManager() 